var currentimage;
var currentindex = -1;
var interval;
function showbanner(index){
	if(index < $('#banner img').length){
		var indeximage = $('#banner img')[index];
		if(currentimage){   
			if(currentimage != indeximage ){
				$(currentimage).css('z-index', 2);
				clearTimeout(mytimer);
				$(currentimage).fadeOut(250, function() {
					mytimer = setTimeout('shownext()', 3000);
					$(this).css({'display':'none', 'z-index':1})
				});
			}
		}
		$(indeximage).css({'display':'block', 'opacity':1});
		currentimage = indeximage;
		currentindex = index;
		$('#thumbnails li').removeClass('active');
		$($('#thumbnails li')[index]).addClass('active');
	}
}
function shownext(){
	var len = $('#banner img').length;
	var next = currentindex < (len-1) ? currentindex + 1 : 0;
	showbanner(next);
}
var mytimer;
$(document).ready(function() {
	mytimer = setTimeout('shownext()', 3000);
	shownext(); //loads first image
	$('#thumbnails li').bind('click',function(e){
		var count = $(this).attr('rel');
		showbanner(parseInt(count)-1);
	});
});
